package com.fuxian.dao.mybatisImpl;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;
import com.fuxian.dao.NewsDao;
import com.fuxian.model.News;

@Repository
public class NewsDaoMybatisImpl implements NewsDao {
	@Resource
	private SqlSessionTemplate sqlSessionTemplate;

	public void addNews(News news) {
		sqlSessionTemplate.insert("addNews", news);
	}

	public void deleteNewsById(int id) {
		sqlSessionTemplate.delete("deleteNewsById", id);

	}

	public void modifyNews(News news) {
		sqlSessionTemplate.update("modifyNews", news);

	}


	public News selectNewsById(int id) {
		News news = sqlSessionTemplate.selectOne("selectNewsById", id);
		return news;
	}

	public List<News> selectNewsByCreatetime(Timestamp createTime,int start,int size) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("create_time", createTime);
		map.put("start", start);
		map.put("size", size);
		List<News> list = sqlSessionTemplate.selectList(
				"selectNewsByCreatetime", map);
		return list;
	}

	public List<News> selectAllNews(int start,int size) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("start", start);
		map.put("size", size);
		List<News> list = sqlSessionTemplate.selectList("selectAllNews", map);
		return list;
	}

	public List<News> selectNewsByAuthor(String author, int start, int size) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("author", author);
		map.put("start", start);
		map.put("size", size);
		List<News> list = sqlSessionTemplate.selectList("selectNewsByAuthor",
				map);
		return list;
	}

	public int selectCount() {
		return sqlSessionTemplate.selectOne("selectNewsCount");
	}

}
